layui.use(['form','layer'],function(){
	var form=layui.form;
	form.verify({
		ip:function(value,item){
			if(!isValidIP(value)){
				return 'IP地址输入有误';
			}
		},
		port:function(value,item){
			if(value==""){
				return;
			}
			if(!isInteger(Number(value))){
				return "请输入整数";
			}
		}
	});
	form.on('submit(login)',function(data){
		$.ajax({
			type:"POST",
			url:"./userLogin",
			data:data.field,
			success:function(data){
				let code=data.code;
				if(code==0){
					window.location.href="./loginSSH?userId="+data.data;
				}else{
					layer.alert(data.message,{icon:2});
				}
			},
			error:function(data){
				layer.alert(data);
			}
		});
		return false;
	});
});

function isValidIP(ip) {//判断IP地址
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    return reg.test(ip);
}

function isInteger(obj) {//判断是否是整数
 return (obj | 0) === obj
}